import glob

dic = {}

for file_name in glob.glob('THUOCL_*.txt'):
	f = open(file_name, 'r', encoding='utf-8')
	for line in f:
		try:
			word, cnt = line.split()
			for hz in word:
				dic.setdefault(hz, 0)
				dic[hz] += 1	# int(cnt)
		except Exception:
			print(file_name, line)
			exit()
	f.close()

dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
f = open('hz-freq.txt', 'w', encoding='utf-8')
n = 0
for hz, freq in dic:
	print(hz, '\t', freq, sep='', file=f)
	#print(hz, file=f)
	n = n + 1
f.close()
